package com.base.mail;

import android.content.Intent;
import android.net.Uri;
import android.text.TextUtils;
import android.view.View;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.base.commonlib.base.CBaseBarActivity;
import com.base.commonlib.base.CBaseBarMvpActivity;
import com.base.commonlib.base.CBaseMvpActivity;
import com.base.commonlib.http.RealNetWorkUtil;
import com.base.commonlib.http.utils.CallBackImpl;
import com.base.mail.bean.ContractInfo;
import com.base.mail.databinding.ActivityMaildetailBinding;

import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;

/**
 * Created by weikailiang on 2019/9/24.
 */
@Route(path = "/mail/maildetail")
public class MailDetailActivity extends CBaseBarMvpActivity{
    protected ActivityMaildetailBinding mBinding;
    protected CompositeDisposable mCompositeDisposable=new CompositeDisposable();
    @Autowired
    String userId;
    @Override
    protected int getLayoutResource() {
        return R.layout.activity_maildetail;
    }

    @Override
    protected void init() {
        super.init();
        mBinding = (ActivityMaildetailBinding) mRootBinding;
        setBackNavigation();
        setBarTitle("用户详情");
    }

    @Override
    protected void start() {
        showPb();
        Disposable enqueue = RealNetWorkUtil.get().method("api-organization/user").addParams("id",userId)
                .build().enqueue(ContractInfo.class, new CallBackImpl<ContractInfo>() {
                    @Override
                    public void onError(int code, String msg, String errMsg) {
                        hidePb();
                    }

                    @Override
                    public void onNext(ContractInfo users) {
                        hidePb();
                        mBinding.setEntity(users);
                    }
                });

        mCompositeDisposable.add(enqueue);
        mBinding.btnCall.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (!TextUtils.isEmpty(mBinding.tvMobile.getText().toString())){
                    callPhone(mBinding.tvMobile.getText().toString());
                }else if (!TextUtils.isEmpty(mBinding.tvWorkNum.getText().toString())){
                    callPhone(mBinding.tvWorkNum.getText().toString());
                }else if (!TextUtils.isEmpty(mBinding.tvShortNum.getText().toString())){
                    callPhone(mBinding.tvShortNum.getText().toString());
                }else {
                    showMes("未查到电话号码");
                }

            }
        });
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mCompositeDisposable != null&&mCompositeDisposable.isDisposed()){
            mCompositeDisposable.dispose();
        }
    }
    public void callPhone(String phoneNum) {
        Intent intent = new Intent(Intent.ACTION_DIAL);
        Uri data = Uri.parse("tel:" + phoneNum);
        intent.setData(data);
        startActivity(intent);
    }
}
